﻿create function [String].[Stub] ( @p_String varchar(max) )
returns varchar(max) as
begin

  declare @returnString varchar(max) = String.Deaccentuate( String.ToLower( String.Trim( @p_String ) ) );

  while PatIndex('%[^0-9a-z ]%', @returnString) > 0
  begin
    set @returnString = Stuff( @returnString, PatIndex( '%[^0-9a-z ]%', @returnString ), 1, ' ' )
  end
  
  while CharIndex( '  ', @returnString ) > 0
  begin
    set @returnString = Replace( @returnString, '  ', ' ' )
  end
  
  set @returnString = Replace( @returnString, ' ', '-' )
  
  return @returnString;

end